//
//  CollectionDetailHeaderViewCell.m
//  Tang
//
//  Created by 邓芮 on 15/12/7.
//  Copyright © 2015年 352324497@qq.com. All rights reserved.
//

#import "CollectionDetailHeaderViewCell.h"

@interface CollectionDetailHeaderViewCell ()

@property (nonatomic, strong) UIView *vertical;
@property (nonatomic, strong) UIView *horizontal;
@end

@implementation CollectionDetailHeaderViewCell

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self)
    {
        CGFloat buttonHeight = 50 * KWidth / 414;
        CGFloat buttonWidth = (KWidth - 2 * KWidth / 414) / 2;
        self.lastest = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.lastest setTitle:@"最新" forState:UIControlStateNormal];
        [self.lastest setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        self.lastest.frame = CGRectMake(0, 0, buttonWidth, buttonHeight);
        [self.lastest addTarget:self action:@selector(lastestAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.lastest];
        
        self.best = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.best setTitle:@"精选" forState:UIControlStateNormal];
        [self.best setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        self.best.frame = CGRectMake(buttonWidth + 2 * KWidth / 414, 0, buttonWidth, buttonHeight);
        [self.best addTarget:self action:@selector(bestAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.best];
        
        self.vertical = [[UIView alloc]initWithFrame:CGRectMake(buttonWidth, 10 * KWidth / 414, 2 * KWidth / 414, 30 * KWidth / 414)];
        self.vertical.backgroundColor = [UIColor lightGrayColor];
        [self.contentView addSubview:self.vertical];
        
        self.horizontal = [[UILabel alloc]initWithFrame:CGRectMake(10 * KWidth / 414, buttonHeight - 2 * KWidth / 414, buttonWidth - 20 * KWidth / 414, 2 * KWidth / 414)];
        self.horizontal.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:self.horizontal];
        
    }
    return self;
}

+ (CGFloat)heightForHeader
{
    return 50 * KWidth / 414;
}

- (void)lastestAction:(UIButton *)button
{
    CGFloat buttonWidth = (KWidth - 2 * KWidth / 414) / 2;
    [UIView animateWithDuration:0.1 animations:^{
        self.horizontal.frame = CGRectMake(10 * KWidth / 414, 48 * KWidth / 414, buttonWidth - 20 * KWidth / 414, 2 * KWidth / 414);
        [self.lastest setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.best setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    }];
}

- (void)bestAction:(UIButton *)button
{
    CGFloat buttonWidth = (KWidth - 2 * KWidth / 414) / 2;
    [UIView animateWithDuration:0.2 animations:^{
        self.horizontal.frame = CGRectMake(10 * KWidth / 414 + buttonWidth, 48 * KWidth / 414, buttonWidth - 20 * KWidth / 414, 2 * KWidth / 414);
        [self.lastest setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.best setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    }];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
